#include "TcpServer.hpp"

#include <iostream>
#include <sys/epoll.h>
#include <unistd.h>
using std::cout;
using std::endl;

void onConnection(wd::TcpConnectionptr tcpconn){
    printf("a new clienfd connected.\n");
}

void onMessage(wd::TcpConnectionptr tcpconn){
    string msg = tcpconn->receive();
    cout << "receive msg:"<< msg << endl;

    tcpconn->send("receive your msg !");
}

void onClose(wd::TcpConnectionptr tcpconn){
    printf("a new clienfd closed.\n");
}

int main()
{
   // wd::Acceptor acceptor(12345,"0.0.0.0");
   // acceptor.ready();

   // wd::EventLoop eventloop(acceptor);
   // 
   // eventloop.setAllCallbacks(onConnection,onMessage,onClose);
   // eventloop.loop();
    
    wd::TcpServer tcpserver(12345,"0.0.0.0");
    tcpserver.setAllCallbacks(onConnection,onMessage,onClose);
    tcpserver.start();
    
    sleep(60);
    tcpserver.stop();

    return 0;
}

